#include <iostream> 
#include <set>
#include <queue>
using namespace std;

int n;
struct triangle{
	int a,b,c,id;
	triangle(int v1,int v2,int v3,int i):a(v1),b(v2),c(v3),id(i){ }
	bool operator < (const triangle & tri) const {
		return this->id<tri.id;
	}
};
void setEdge(vector<vector<int> >& net,int v1,int v2,int v3,bool fromLeftToRight){
	net[v2][v3] = -1;net[v3][v2] = 1;
	net[v3][v1] = -1;net[v1][v3] = 1;
}
triangle adjust(vector<vector<int> >& net,int v1,int v2,int v3,int i){
	int fromLeftToRight = -1;
	triangle ret(0,0,0,-1);
	if( net[v1][v2]!=0 ){
		if( net[v1][v2]==1 ){
			net[v2][v3] = -1;net[v3][v2] = 1;
			net[v3][v1] = -1;net[v1][v3] = 1;
			fromLeftToRight = 1;
		}else{
			net[v1][v3] = -1;net[v3][v1] = 1;
			net[v3][v2] = -1;net[v2][v3] = 1;
			fromLeftToRight = 0;
		}
	} else if( net[v2][v3]!=0 ){
		if( net[v2][v3]==1 ){
			net[v3][v1] = -1;net[v1][v3] = 1;
			net[v1][v2] = -1;net[v2][v1] = 1;
			fromLeftToRight = 1;
		}else{
			net[v2][v1] = -1;net[v1][v2] = 1;
			net[v1][v3] = -1;net[v3][v1] = 1;
			fromLeftToRight = 0;
		}
	}else if( net[v3][v1]!=0){
		if( net[v3][v1]==1 ){
			net[v1][v2] = -1;net[v2][v1] = 1;
			net[v2][v3] = -1;net[v3][v2] = 1;
			fromLeftToRight = 1;
		}else{
			net[v3][v2] = -1;net[v2][v3] = 1;
			net[v2][v1] = -1;net[v1][v2] = 1;
			fromLeftToRight = 0;
		}
	}
	if( fromLeftToRight==1 ) {
		if( v1<v2&& v1<v3) ret = triangle(v1,v2,v3,i);
		if( v2<v1&& v2<v3) ret = triangle(v2,v3,v1,i);
		if( v3<v1&& v3<v2) ret = triangle(v3,v1,v2,i);
 	}
	if( fromLeftToRight==0 ){
		if( v1<v2&& v1<v3) ret = triangle(v1,v3,v2,i);
		if( v2<v1&& v2<v3) ret = triangle(v2,v1,v3,i);
		if( v3<v1&& v3<v2) ret = triangle(v3,v2,v1,i);
	}
	return ret;
}
int main(){
	int m;
	cin >> n >> m;
	set<triangle> out;
	vector<vector<int> > net;
	for(int i=0; i<n+1; i++) net.push_back(vector<int>(n+1,0));
	int t1,t2,t3;
	cin >> t1 >> t2 >> t3;
	net[t1][t2] = -1; net[t2][t1] = 1;
	net[t2][t3] = -1; net[t3][t2] = 1;
	net[t3][t1] = -1; net[t1][t3] = 1;
	if( t1<t2 && t1 <t3) out.insert(triangle(t1,t2,t3,0));
	if( t2<t1 && t2 < t3 ) out.insert(triangle(t2,t3,t1,0));
	if( t3<t1 && t3<t2) out.insert(triangle(t3,t1,t2,0));
	queue<triangle> que;
	for(int i=1; i<m;i++){
		int v1,v2,v3;
		cin >> v1 >> v2 >> v3;
		triangle tri = adjust(net,v1,v2,v3,i);
		if( tri.id!=-1 ) out.insert(tri);
		else que.push(triangle(v1,v2,v3,i));
		
	}
	while( !que.empty() ){
		triangle tri = que.front();
		cout << tri.a << " "<<tri.b <<" " << tri.c <<endl;
		triangle adj = adjust(net,tri.a,tri.b,tri.c,tri.id);
		if( adj.id!=-1 ){
			out.insert(adj);
		}else que.push(tri);
		que.pop();
	}
	for(auto it=out.begin(); it!=out.end(); it++){
		cout << (*it).a << " "<<(*it).b <<" " << (*it).c <<endl;
	}
	return 0;
}
